package aimpublisher;

import gui.GUI;

import javax.swing.SwingUtilities;

import communication.AIM;

import configuration.Configuration;

public class AIMPublisher {
	private static Configuration configuration = new Configuration("test.xml");

	public static Configuration getConfiguration() {
		return AIMPublisher.configuration;
	}

	public static void main(final String[] args) {
		final Runnable doWorkRunnable = new Runnable() {
			public void run() {
				GUI.doGUI();
			}
		};
		SwingUtilities.invokeLater(doWorkRunnable);

		new Thread(new AIM()).start();
		Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
			@Override
			public void run() {
				System.err.println("Writing configuration to file.");
				AIMPublisher.getConfiguration().writeFile();
			}
		}));
	}

	public static void setConfiguration(final Configuration configuration) {
		AIMPublisher.configuration = configuration;
	}
}